/**
*	Function: valid_date
*	
*	Checks if the the given parameters forms a valid date. If is a valid one then returns a Date object, else case, returns false.
*
*	@param day - int value
*	@param month - int value
*	@param year - int value
*
*/
function valid_date(day, month, year){

    if (isNaN(day) || isNaN(month) || isNaN(year)) {
        return false;
    }
    
    var leap = 0;
    var err = 0;

	
   err = 0;

   if (year == 0) {
      err = 20;
   }

   if ((month < 1) || (month > 12)) {
      err = 21;
   }

   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12))) {
      err = 25;
   }
   if ((day > 30) && ((month == 04) || (month == 06) || (month == 09) || (month == 11))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      return false;
   }
   
      	  
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      var date = new Date();
      date.setDate(day);
      date.setMonth(month - 1);
      date.setFullYear(year);
      
      
      return date;
   }
   /* Error-message if err != 0 */
   else {
	return false;
   }
}
